IdeaBlade.EntityModel.Compat Assembly > IdeaBlade.EntityModel Namespace > Coroutine Class > Start Method : Start(Func<CoroutineOperation,IEnumerable<INotifyCompleted>>,Action<CoroutineOperation>) Method |
'Declaration
Public Overloads Shared Function Start( _ ByVal coroutine As Func(Of CoroutineOperation,IEnumerable(Of INotifyCompleted)), _ Optional ByVal completedHandler As Action(Of CoroutineOperation) _ ) As CoroutineOperation
'Usage
Dim coroutine As Func(Of CoroutineOperation,IEnumerable(Of INotifyCompleted)) Dim completedHandler As Action(Of CoroutineOperation) Dim value As CoroutineOperation value = Coroutine.Start(coroutine, completedHandler)
Use this overload of the Start method when your iterator accepts a CoroutineOperation as an argument. You can use the CoroutineOperation to track the prior operations within the iterator.
public void CoroutineSample2() { Coroutine.Start(Sample2Actions, (op) => { SaveResult sr = op.Result as SaveResult; MessageBox.Show("Save count = " + sr.SavedEntities.Count().ToString()); }); } private IEnumerable<INotifyCompleted> Sample2Actions(CoroutineOperation coop) { // Sample showing use of the CoroutineOperation during processing, // and returning a final result to the Coroutine. var mgr = new DomainModelEntityManager(); // Get a few customers yield return mgr.Customers.Take(2).ExecuteAsync(); // See what we got. var custs = (coop.Notifications.Last() as EntityQueryOperation<Customer>).Results; // Now get a few employees yield return mgr.Employees.Take(3).ExecuteAsync(); // See what we've got var emps = (coop.Notifications.Last() as EntityQueryOperation<Employee>).Results; // We can also make changes and save. emps.ForEach(e => e.Notes = "Updated at " + DateTime.Now.ToString()); yield return mgr.SaveChangesAsync(); // Let's return the final result too. SaveResult sr = (coop.Notifications.Last() as EntitySaveOperation).SaveResult; yield return Coroutine.Return(sr); }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2